﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Daphne.GameShared
{
    /// <summary>
    /// Interface for reading situation on the board
    /// </summary>
    public interface IGameBoard
    {
        int Size
        { get; }

        enumFigureType GetField(Position pos);
    }

    /// <summary>
    /// Interface for gameboard accessed by the game-editor service
    /// </summary>
    public interface IGameBoardForEditor
    {
        enumFigureColor GetFieldColor(Position pos);
        enumFigureType GetField(Position pos);
        void PlaceFigure(Position pos, enumFigureType figureType);
        void ClearField(Position pos);
        void ClearBoard();
        void SetStartupPosition();
        void SetSTM(enumFigureColor stm);
        enumFigureColor GetSTM();
        BitBoard PackPosition();
        void UnpackPosition(BitBoard bb);
    }

    /// <summary>
    /// Interface for gameboard for entering user moves
    /// </summary>
    public interface IUserMoveEntering
    {
        /// <summary>
        /// Determines whether specified figure can move
        /// </summary>
        bool CanFigureMove(Position source);

        /// <summary>
        /// Returns target fields for given figure
        /// </summary>
        List<Position> GetFigureTargetFields(Position source);

        /// <summary>
        /// Returns figures which player can move with
        /// </summary>
        List<Position> GetFiguresToMove();

        /// <summary>
        /// Performs one move step
        /// </summary>
        void DoMoveStep(Position source, Position target);

        /// <summary>
        /// Returns position of the captured piece for the last move step
        /// </summary>
        Position? IsLastMoveStepCapturing();

        /// <summary>
        /// Determines whether player's move continues
        /// </summary>
        bool DoesMoveContinue();

        /// <summary>
        /// Final method to complete the move
        /// Mainly run after finishing the animation
        /// </summary>
        void FinalizeMove();
    }

    /// <summary>
    /// Interface to the game editor business logic
    /// </summary>
    public interface IGameEditor
    {
        /// <summary>
        /// Notification that editor mode has been started
        /// Used for cleaning internal variables
        /// </summary>
        void NotifyEditModeStarted();

        /// <summary>
        /// Board manipulation methods
        /// </summary>
        enumFigureColor GetFieldColor(Position pos);
        enumFigureType GetField(Position pos);       
        void PlaceFigure(Position pos, enumFigureType figureType);
        void ClearField(Position pos);
        void ClearBoard();
        void SetStartupPosition();
        void SetSTM(enumFigureColor stm);
        enumFigureColor GetSTM();

        /// <summary>
        /// Puts position given by FEN string
        /// </summary>
        void SetFENPosition(string fen);

        /// <summary>
        /// Stack methods
        /// </summary>
        void Undo();
        void Redo();
        bool CanUndo();
        bool CanRedo();

        /// <summary>
        /// Restores the previous position 
        /// before the beginning of editting mode
        /// </summary>
        void RestorePreviousPosition();
    }

    /// <summary>
    /// Library record
    /// </summary>
    public class LibraryRecord
    {
        public string LibraryName
        { get; set; }

        public string Author
        { get; set; }

        public string URL
        { get; set; }

        public string LicenseFile
        { get; set; }

        public override string ToString()
        {
            return LibraryName;
        }
    }


    /// <summary>
    /// Interface to the License parser
    /// </summary>
    public interface ILicensesParser
    {
        // output resuls
        string ProgramName
        { get; set; }

        string ProgramURL
        { get; set; }

        List<LibraryRecord> LibraryRecords
        { get; set; }

        string LicenseFileContent
        { get; }

        /// <summary>
        /// The main parsing method
        /// </summary>
        Task Parse();

        /// <summary>
        /// Loads the lincese file async for given library
        /// </summary>
        /// <param name="fileName"></param>
        Task LoadLicenseFileAsync(string fileName);
    }

}
